/*******************************************************************************
BaseParser.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-08-07

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/

#ifndef _BASEPARSER_H_
#define _BASEPARSER_H_

#include "SceneDat.h"

class CBaseParser
{
public:

	static inline void MoveToBegin(LPCTSTR& p)
	{
		while(*p)
		{
			if(*p == _T('\t') || *p == _T(' '))
			{
				p++;
			}
			else break;
		}
	}
	static inline void MoveToEnd(LPCTSTR& p)
	{
		while(*p)
		{
			if(*p == _T('\t') || *p == _T(' '))
			{
				break;
			}
			else
			{
				p++;
			}
		}
	}

	static inline CString ParseOf(LPCTSTR& p)
	{
		MoveToBegin(p);

		LPCTSTR pBegin = p;

		MoveToEnd(p);

		LPCTSTR pEnd = p;
		return CString(pBegin, pEnd-pBegin);
	}

	static inline int ParseOf(LPCTSTR& p, int nDef)
	{
		int nValue = nDef;
		CString s = ParseOf(p);
		
		if(!s.IsEmpty())
		{
			nValue = atoi(s);
		}
		return nValue;
	}

	static inline float ParseOf(LPCTSTR& p, float fDef)
	{
		float fValue = fDef;
		CString s = ParseOf(p);
		
		if(!s.IsEmpty())
		{
			fValue = (float)atof(s);
		}
		return fValue;
	}
	
};

#endif//_BASEPARSER_H_